﻿// Inner Fire 游戏引擎库
// 纹理类
//
// Copyright (c) 2023 by 尔西大帝. All rights reserved.
//
// 用于纹理
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2024-11-22

#pragma once

#include <array>
#include <dx/core/dx_core.h>
#include <dx/core/dx_element.h>
#include <image.h>
#include <unordered_map>
#include <memory>

namespace ifire::dx {

constexpr auto DEFAULT_TEXTURE_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM;

class DxTexture : public DxElement {
public:
  DxTexture(int index, ikit::sstr name, TextureType type);
  DxTexture(const DxTexture& rhs) = delete;
  DxTexture& operator=(const DxTexture& rhs) = delete;
  ~DxTexture() = default;

  void CreateFromFile(
      ID3D12Device* device, ID3D12GraphicsCommandList* cmd, const std::string_view&
      filename, bool is_flip);
  void CreateFromImage(ID3D12Device* device, ID3D12GraphicsCommandList* cmd,
      const ikit::ImageData& data);
  inline ID3D12Resource* Resource() const { return resource_.Get(); }
  inline ID3D12Resource* Uploader() const { return uploader_.Get(); }
  inline TextureType Type() const { return type_; }

  static TextureType ReadType(ikit::sstr name);

private:
  TextureType type_;
  ComPtr<ID3D12Resource> resource_ = nullptr;
  ComPtr<ID3D12Resource> uploader_ = nullptr;
};

using TexturePtr = std::unique_ptr<DxTexture>;

} // namespace ifire::dx
